<?php

use App\Http\Controllers\UserController;
use App\Http\Controllers\StaffController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\PackagesController;
use App\Http\Controllers\ContainerController;
use App\Http\Controllers\RouteController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/
// TODO : 快递员第七个接口没写
Route::group(['prefix' => '/v1'], function () {
    Route::controller(AuthController::class)->group(function () {
        Route::post("/auth/signup", "userRegister");
        Route::post("/auth/signin", "userLogin");
        Route::post("/auth/signout", "userLogout");
        Route::post("/staff/signin", "staffLogin");
        Route::post("/staff/signout", "staffLogout");
    });

    Route::controller(PackagesController::class)->group(function () {
        Route::middleware("auth.authorization")->group(function () {
            Route::get("/track/{tracking_number}" , "showByUser");
            Route::post("/package" , "sendPackage");
            Route::get("/package" , "getUserPackages");
            Route::patch("/package/{package_id}" , "returnPackage");
            Route::post("/courier/package/pickedup/pack" , "packing");
        });
        Route::middleware(['auth.authorization' , 'auth.courtier'])->group(function () {
            Route::get("/courier/package/pending" , "getPendingPickupPackage");
            Route::post("/courier/package/pickup/carry" , "pickedUp");
            Route::get("/courier/package/delivery/pending" , "getCampusPendingPackage");
            Route::post("/courier/package/delivery/carry" , "delivery");
            Route::get("/courier/package/delivering/carried" , "getDeliveryPackage");
        });
        Route::middleware(['auth.authorization' , 'auth.trucker'])->group(function () {
            Route::get("/trucker/container/{container_id}/packages" , "getByContainer");
        });
    });

    Route::controller(StaffController::class)->group(function () {
        Route::get("/staff/information" , "getInfo");
        Route::post("/courier/online-toggle" , "changeOnline");
    })->middleware("auth.authorization");

    Route::controller(ContainerController::class)->group(function () {
        Route::get("/trucker/container" , "getByStaff");
        Route::get("/trucker/container/campus" , "getByCampus");
        Route::patch("1/trucker/container/unload/{container_id}" , "unloadContainer");
    })->middleware(["auth.authorization" , "auth.trucker"]);

    Route::controller(RouteController::class)->group(function () {
        Route::get("/trucker/route" , "getRoutes");
        Route::get("/trucker/route/next" , "getNextRoute");
    })->middleware(["auth.authorization" , "auth.trucker"]);
});
